//
//  TTWelcomeViewController.m
//  TTWeibo
//
//  Created by 陶宏路 on 16/7/24.
//  Copyright © 2016年 陶路路. All rights reserved.
//

#import "TTWelcomeViewController.h"
#import "TTWelcomeModel.h"
#import "TTWelconmeModel.h"
@interface TTWelcomeViewController ()

@property (nonatomic,strong)  TTWelcomeModel * model;

@property (nonatomic,strong) UIImageView * imageView;
@property (nonatomic,strong) UIImageView * userImage;
@property (nonatomic,strong) UILabel * titleLable;

@end

@implementation TTWelcomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor orangeColor];
    
    self.model = [TTWelcomeModel sharedManager];
    
    [self setUpUI];
    
}

-(void)viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:YES];
    
    [self starAnimation];
    
}

-(void)starAnimation{
    
    [self.userImage mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.view).offset(-500);
    }];
    
    [UIView animateWithDuration:3 delay:1 usingSpringWithDamping:0.6 initialSpringVelocity:0 options:0 animations:^{
        
        [self.view layoutIfNeeded];
        
    } completion:^(BOOL finished) {
    
        [UIView animateWithDuration:2 animations:^{
            
            self.titleLable.alpha = 1;
            
        } completion:^(BOOL finished) {
            
            [[NSNotificationCenter defaultCenter] postNotificationName:@"WelcomeViewController" object:self];
        }];
    
        
    }];
    
}

-(void)setUpUI{
    
    [self.view addSubview:self.imageView];
    [self.view addSubview:self.titleLable];
    [self.view addSubview:self.userImage];
    
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
    
        make.top.leading.trailing.bottom.equalTo(self.view);
        
    }];
    
    [self.userImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.width.height.width.equalTo(@90);
        make.bottom.equalTo(self.view).offset(-200);
    }];
    
    [self.titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.userImage.mas_bottom).offset(30);
    }];
}

-(UIImageView *)imageView{
    
    if (_imageView == nil) {
        
        _imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ad_background"]];

    }
    
    return _imageView;
}

-(UIImageView *)userImage{
    
    if (_userImage == nil) {
        
        _userImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"avatar_default_big"]];
        
        NSURL * url = [NSURL URLWithString:self.model.model.avatar_large];
        
        _userImage.layer.cornerRadius = 45;
        _userImage.layer.borderWidth = 2;
        _userImage.layer.borderColor = [UIColor orangeColor].CGColor;
        _userImage.layer.masksToBounds = YES;
       
        [_userImage sd_setImageWithURL:url];
    }
    
    return _userImage;
}

-(UILabel *)titleLable{
    
    if (_titleLable == nil) {
        
        _titleLable = [[UILabel alloc]init];
        _titleLable.font = [UIFont systemFontOfSize:20];
        _titleLable.textColor = [UIColor blackColor];
        _titleLable.text = @"欢迎回来";
        _titleLable.alpha = 0;
    }
    
    return _titleLable;
}
@end
